package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ParcelInventory;
import com.ruoyi.system.service.IParcelInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 快递入库Controller
 * 
 * @author ruoyi
 * @date 2024-05-18
 */
@RestController
@RequestMapping("/system/inventory")
public class ParcelInventoryController extends BaseController
{
    @Autowired
    private IParcelInventoryService parcelInventoryService;

    /**
     * 查询快递入库列表
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParcelInventory parcelInventory)
    {
        startPage();
        List<ParcelInventory> list = parcelInventoryService.selectParcelInventoryList(parcelInventory);
        return getDataTable(list);
    }

    /**
     * 导出快递入库列表
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:export')")
    @Log(title = "快递入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParcelInventory parcelInventory)
    {
        List<ParcelInventory> list = parcelInventoryService.selectParcelInventoryList(parcelInventory);
        ExcelUtil<ParcelInventory> util = new ExcelUtil<ParcelInventory>(ParcelInventory.class);
        util.exportExcel(response, list, "快递入库数据");
    }

    /**
     * 获取快递入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:query')")
    @GetMapping(value = "/{parcelId}")
    public AjaxResult getInfo(@PathVariable("parcelId") Long parcelId)
    {
        return success(parcelInventoryService.selectParcelInventoryByParcelId(parcelId));
    }

    /**
     * 新增快递入库
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:add')")
    @Log(title = "快递入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParcelInventory parcelInventory) throws Exception {
        return toAjax(parcelInventoryService.insertParcelInventory(parcelInventory));
    }

    /**
     * 修改快递入库
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:edit')")
    @Log(title = "快递入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParcelInventory parcelInventory)
    {
        return toAjax(parcelInventoryService.updateParcelInventory(parcelInventory));
    }

    /**
     * 删除快递入库
     */
    @PreAuthorize("@ss.hasPermi('system:inventory:remove')")
    @Log(title = "快递入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{parcelIds}")
    public AjaxResult remove(@PathVariable Long[] parcelIds)
    {
        return toAjax(parcelInventoryService.deleteParcelInventoryByParcelIds(parcelIds));
    }
}
